from tkinter import messagebox
from shutil import copyfile
from utils import *
import os
import sys
src_path=r"C:\Users\ASUS\Desktop\e_m_voc"
des_path=os.path.join("\\".join(src_path.split("\\")[:-1]),src_path.split("\\")[-1]+"_yolo") 
# print(des_path)
if not os.path.exists(os.path.join(src_path,"classes.txt")):
    messagebox.showerror("错误", "缺少classes文件")
    os._exit(999)
if not os.path.exists(des_path):os.makedirs(des_path)

all_file=os.listdir(src_path)
for file in all_file:
    if file.split(".")[1]=="jpg" or file.split(".")[1]=="png" or file.split(".")[1]=="txt":
        copyfile(os.path.join(src_path,file),os.path.join(des_path,file))
    if file.split(".")[1]=="xml":
        mydata,height,width=voc2mydata(os.path.join(src_path,file))
        content=dress_mydata(mydata,get_all_cate_str(os.path.join(src_path,"classes.txt")),height,width)
        with open(os.path.join(des_path,file.split(".")[0]+".txt"),"w", encoding='utf-8')as f:
            f.write(content)
    if file.split(".")[1]=="json":
        mydata,height,width=coco2mydata(os.path.join(src_path,file))
        content=dress_mydata(mydata,get_all_cate_str(os.path.join(src_path,"classes.txt")),height,width)
        with open(os.path.join(des_path,file.split(".")[0]+".txt"),"w", encoding='utf-8')as f:
            f.write(content)










